package com.taomu.app.zongchouhuli.moudle.home.contract.impl;

import com.taomu.app.zongchouhuli.entity.BaseChangeResponse;
import com.taomu.app.zongchouhuli.http.api.HttpObserver;
import com.taomu.app.zongchouhuli.http.api.Request;
import com.taomu.app.zongchouhuli.http.res.ResMainProductListEntity;
import com.taomu.app.zongchouhuli.http.res.ResProductEntity;
import com.taomu.app.zongchouhuli.moudle.home.contract.HomeSearchContract;
import com.taomu.app.zongchouhuli.moudle.index.entity.ProductEntity;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;

public class HomeSearchPresenter implements HomeSearchContract.Presenter {

    private HomeSearchContract.View mContractView;

    private CompositeDisposable disposable;

    public HomeSearchPresenter(HomeSearchContract.View mContractView){
        this.mContractView = mContractView;
        this.disposable = new CompositeDisposable();
    }

    @Override
    public void getSearchList(String content) {
        setSearchList(content);
    }

    @Override
    public void getMoreProductList(String name, String ship, String take) {
        Request.getIntence().getProductListData(name,ship,take,"","")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new HttpObserver<ResMainProductListEntity>(mContractView,disposable,true) {
                    @Override
                    public void onNext(ResMainProductListEntity resProductEntities) {
                        if(mContractView != null){
                            mContractView.setSearchList(resProductEntities);
                        }
                    }
                });
    }

    @Override
    public void detch() {

    }

    private void setSearchList(String content){
        List<ProductEntity> entities = new ArrayList<>();
        for(int i=0;i<4;i++){
            ProductEntity entity = new ProductEntity();
            entity.setTitle(content+":::::"+i);
            entity.setLimitNum("");
            entity.setPrice("¥666");
            entity.setIncome("最高收益3.25%");
            entities.add(entity);
        }
//        if(mContractView != null){
//            mContractView.setSearchList(entities);
//        }
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onDetch() {
        mContractView = null;
        if(disposable != null){
            disposable.dispose();
            disposable = null;
        }
    }
}
